let express = require("express")();
let expressStatic = require("express-static");
let mysql = require('mysql');
let port = 81;

// 规划一个数据库链接
let sql = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '123456',
    database: 'chonyoo',
    timezone: "08:00"
});

// 尝试链接
sql.connect();

express.get('/select', function(request, response) {
    sql.query(`SELECT * FROM list`, (error, data) => {
        if (error) {
            console.log(error);
            response.send("error");
        } else {
            response.send(data)
        }
    })
})


express.get('/list1', function(request, response) {
    sql.query(`SELECT * FROM list1`, (error, data) => {
        if (error) {
            console.log(error);
            response.send("error");
        } else {
            response.send(data)
        }
    })
})




// 如果接收到来自前端的静态文件请求的话，我该去哪里去给他找文件
express.use(expressStatic(__dirname + '/static'));
console.log(`running at ${port}`)
express.listen(port)